<template>
    <el-header style="text-align: right; font-size: 12px">
        <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>个人中心</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        <el-button @click="open()">退出</el-button>
    </el-header>
</template>
<script>
    export default {
        name: 'Header',
        methods:{
            //打开确定框
            open(index, row, id) {
                this.$confirm('确定退出, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$message({
                        type: 'success',
                        message: '退出成功!'
                    });
                    this.userExit()
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消退出',
                    });
                });
            },
            userExit(){
                this.axios.post('http://120.26.99.230:8092/user/userExit').then(res =>
                {
                    console.log(res)
                    if(res.data.is == true)
                    {
                        //清除登录信息 先置空 后面再处理
                        localStorage.removeItem("token")
                        this.$router.push('/')
                        this.$message.success(res.data.msg);
                    }
                    else
                    {
                        this.$message.error(res.data.msg);
                    }
                })
            }
        }
    }
</script>
<style>
</style>